package www.bplead.com.mydemo.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.PauseOnScrollListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import www.bplead.com.controller.action.user.event.UserInfoRequest;
import www.bplead.com.controller.action.user.event.UserInfoResponse;
import www.bplead.com.mydemo.R;
import www.bplead.com.mydemo.adapter.LoadImageAdapter;

public class LoadImageActivity extends BaseActivity implements View.OnClickListener{

    private static final String TAG = "LoadImageActivity";
    private LoadImageAdapter imageAdapter;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image_loader);

        listView = (ListView) this.findViewById(R.id.userinfo_lv);
        //pauseOnsceoll和pauseOnFling都设置为true，表示滑动停止后才进行加载图片,可以有效的解决因滑动时加载图片导致页面卡顿的问题
        listView.setOnScrollListener(new PauseOnScrollListener(ImageLoader.getInstance(), true, true));

        sendRequest();
    }

    private void sendRequest(){
        UserInfoRequest request = new UserInfoRequest();
        EventBus.getDefault().post(request);
    }

    @Subscribe
    public void getUserList(UserInfoResponse response) {
        Log.v(TAG, "getUserList function : " + response.userInfoList);

        imageAdapter = new LoadImageAdapter(this,response.userInfoList);
        listView.setAdapter(imageAdapter);
    }

    @Override
    public void onClick(View v) {

    }

}
